package com.scsystem.xysc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.scsystem.xysc.aop.LogOperations;
import com.scsystem.xysc.pojo.ActionLog;
import com.scsystem.xysc.pojo.vo.ReturnResult;
import com.scsystem.xysc.service.ActionLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/log")
@Tag(name = "日志接口")
public class LogController {

    @Resource
    private ActionLogService actionLogService;

    @GetMapping("/select")
    @Operation(summary = "模糊查询日志信息，不给条件就全查，返回分页对象")
    @Parameters({
            @Parameter(name = "condition", description = "条件"),
            @Parameter(name = "pageNumber", description = "页码", required = true),
            @Parameter(name = "count", description = "每页显示的数量", required = true)
    })
    public ReturnResult<Page<ActionLog>> selectLog(
            @RequestParam(value = "condition", required = false) String condition,
            @RequestParam("pageNumber") int pageNumber,
            @RequestParam("count") int count) {

        Page<ActionLog> logPage = actionLogService.getLogPage(condition, pageNumber, count);

        if (logPage.getRecords().isEmpty()) {
            return new ReturnResult<>(400, "无数据", logPage);
        }
        return new ReturnResult<>(200, "查询成功", logPage);
    }

}
